package com.software.usercenter.repository;

import com.software.usercenter.entity.StudentInfo;
import org.springframework.data.domain.Example;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

@Transactional
public interface StudentInfoRepository extends JpaRepository<StudentInfo, Integer>, JpaSpecificationExecutor<StudentInfo> {

    StudentInfo findStudentInfoByUserId(String userId);
    StudentInfo findStudentInfoByUserName(String userName);

    void deleteStudentInfoByUserId(String userId);

    //判断用户名是否存在
    List<StudentInfo> findStudentInfosByUserName(String param_username);

    //验证用户名密码是否正确
    List<StudentInfo> findStudentByUserNameAndPassword(String userName, String password);

    @Modifying
    @Query(value = "update student_info set user_name=?2,nick_name=?3,real_name=?4,gender=?5,school=?6,icon=?7 where user_id=?1",nativeQuery = true)
    void updateStudent(String userId, String userName, String nickName, String realName, String gender, String school,String icon);

    //查找某班级里的所有学生
    List<StudentInfo> findStudentsByClassId(String classId);

    @Modifying
    @Query(value = "update student_info set password=?2 where user_name=?1",nativeQuery = true)
    void updatePassword(String userName, String password);

    @Modifying
    @Query(value = "delete from student_info where user_name=?1",nativeQuery = true)
    void deleteStudent(String userName);
}
